/**
 * 
 */
package optimization.naturalOptimization.evolutionaryAlgorithm.evolutionStrategy;

import optimization.naturalOptimization.NaturalOptimization;
import optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.evaluator.StandardEvaluator;
import optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.mutation.DoubleArrayMutation;
import optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.recombination.CopyRecombination;
import optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.selection.CommaSelector;
import optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.selection.Selector;
import optimization.naturalOptimization.population.individual.EA.DoubleArrayEAIndividual;

/**
 * This class provides a standard Mu,Lambda-ES
 * 
 * @author Kevin Wagner
 * @version 1.0
 */
public class MuCommaLambdaES extends EvolutionStrategy {

	/*
	 * (non-Javadoc)
	 * 
	 * @see optimization.IdentificationI#getIndentification()
	 */
	@Override
	public String getIndentification() {
		return "(Mu,Lambda)-Evolution Strategy";
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see optimization.OptimizationI#init()
	 */
	@SuppressWarnings({ "unchecked" })
	public boolean init() {
		super.init();
		addOperator(new CopyRecombination(this));
		addOperator(new DoubleArrayMutation(this));
		addOperator(new StandardEvaluator(this));
		Selector s=new CommaSelector(this);
		addOperator(s);
		for (int i = 0; i < getLambda(); i++) {
			getProgenyPopulation().addIndividual(
					new DoubleArrayEAIndividual(getProgenyPopulation()));
			getProgenyPopulation().getIndividual(i).setPosition(
					getSearchSpace().createRandomPosition());
			((DoubleArrayEAIndividual) getProgenyPopulation().getIndividual(i))
					.setStrategyComponent((double[]) getSearchSpace()
							.createPositiveVector(0.05));
		}
		try {
			getFitness().getFitness(getProgenyPopulation());
		} catch (Exception e) {
			pushError(e);
		}
		s.work();//Selection
		setResult(getCurrentBestFitness());
		exportIndividualData();
		setStatus(NaturalOptimization.inizialized);
		return true;
	}

}
